package com.java28.rbac.service.impl;

import com.java28.rbac.mapper.RoleMapper;
import com.java28.rbac.pojo.Role;
import com.java28.rbac.pojo.RoleExample;
import com.java28.rbac.pojo.RoleExample.Criteria;
import com.java28.rbac.service.RoleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RoleServiceImpl implements RoleService {

    @Autowired(required=false)
    RoleMapper roleMapper;

    @Override
    public List<Role> findAll() {
//        RoleExample roleExample = new RoleExample();
        return roleMapper.selectByExample(null);
    }

    @Override
    public List<Role> findAllByLike(String like) {
        like = "%"+like+"%";
        RoleExample roleExample = new RoleExample();
        Criteria criteria = roleExample.createCriteria();
        if (like!="" || like!=null){
            criteria.andRolenameLike(like);
        }
        return roleMapper.selectByExample(roleExample);
    }
}
